package com.google.code.mochaccino.framework.freemarker;

import com.google.code.mochaccino.framework.freemarker.exception.TemplateExceptionHandlerSlf4j;
import javax.inject.Provider;
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.TemplateExceptionHandler;

/** Template Configuration Provider */
public class TemplateConfigurationProvider implements Provider<TemplateConfiguration> {
	private BeansWrapper             objectWrapper    = BeansWrapper.getDefaultInstance();
	private String                   dateFormat       = "yyyy/MM/dd";
	private String                   dateTimeFormat   = "yyyy/MM/dd HH:mm:ss";
	private String                   encoding         = "UTF-8";
	private String                   timeFormat       = "HH:mm:ss";
	private TemplateExceptionHandler exceptionHandler = new TemplateExceptionHandlerSlf4j();

	/** Constructor */
	public TemplateConfigurationProvider( BeansWrapper objectWrapper, TemplateExceptionHandler exceptionHandler, String encoding ) {
		this();
		this.objectWrapper = objectWrapper;
		this.exceptionHandler = exceptionHandler;
		this.encoding = encoding;
	}

	/** Constructor */
	public TemplateConfigurationProvider() {
	}

	@Override
	public TemplateConfiguration get() {
		TemplateConfiguration bean = new TemplateConfiguration();
		bean.setExceptionHandler( exceptionHandler );
		bean.setObjectWrapper( objectWrapper );
		bean.setDateFormat( dateFormat );
		bean.setDateTimeFormat( dateTimeFormat );
		bean.setTimeFormat( timeFormat );
		bean.setEncoding( encoding );
		return bean;
	}

	public String getDateFormat() {
		return dateFormat;
	}

	public void setDateFormat( String dateFormat ) {
		this.dateFormat = dateFormat;
	}

	public String getDateTimeFormat() {
		return dateTimeFormat;
	}

	public void setDateTimeFormat( String dateTimeFormat ) {
		this.dateTimeFormat = dateTimeFormat;
	}

	public String getEncoding() {
		return encoding;
	}

	public void setEncoding( String encoding ) {
		this.encoding = encoding;
	}

	public TemplateExceptionHandler getExceptionHandler() {
		return exceptionHandler;
	}

	public void setExceptionHandler( TemplateExceptionHandler exceptionHandler ) {
		this.exceptionHandler = exceptionHandler;
	}

	public BeansWrapper getObjectWrapper() {
		return objectWrapper;
	}

	public void setObjectWrapper( BeansWrapper objectWrapper ) {
		this.objectWrapper = objectWrapper;
	}

	public String getTimeFormat() {
		return timeFormat;
	}

	public void setTimeFormat( String timeFormat ) {
		this.timeFormat = timeFormat;
	}
}
